
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/01/2012 15:51:38
-- Generated from EDMX file: D:\team-hotel-project\src\Hotel.llc\Hotel.Module.Management\DataRepository\ManagementEntityModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ManagementDatabae];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_OrderIncludedServices]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IncludedServices] DROP CONSTRAINT [FK_OrderIncludedServices];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderRoomPackage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoomPackages] DROP CONSTRAINT [FK_OrderRoomPackage];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Orders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Orders];
GO
IF OBJECT_ID(N'[dbo].[RoomPackages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoomPackages];
GO
IF OBJECT_ID(N'[dbo].[IncludedServices]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IncludedServices];
GO
IF OBJECT_ID(N'[dbo].[Assignments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Assignments];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [FName] nvarchar(max)  NOT NULL,
    [InDate] datetime  NOT NULL,
    [OutDate] datetime  NOT NULL,
    [LName] nvarchar(max)  NOT NULL,
    [NumberOfPeople] int  NOT NULL,
    [NumberOfRooms] int  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [TotalCost] int  NULL,
    [State] int  NOT NULL,
    [RoomType] int  NOT NULL
);
GO

-- Creating table 'RoomPackages'
CREATE TABLE [dbo].[RoomPackages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] int  NOT NULL,
    [OrderId] int  NOT NULL
);
GO

-- Creating table 'IncludedServices'
CREATE TABLE [dbo].[IncludedServices] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrderId] int  NOT NULL,
    [Value] int  NOT NULL
);
GO

-- Creating table 'Assignments'
CREATE TABLE [dbo].[Assignments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [RoomNumber] int  NOT NULL,
    [ServiceID] int  NOT NULL,
    [WorkerLogin] nvarchar(max)  NULL,
    [WorkerType] int  NOT NULL,
    [State] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RoomPackages'
ALTER TABLE [dbo].[RoomPackages]
ADD CONSTRAINT [PK_RoomPackages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IncludedServices'
ALTER TABLE [dbo].[IncludedServices]
ADD CONSTRAINT [PK_IncludedServices]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Assignments'
ALTER TABLE [dbo].[Assignments]
ADD CONSTRAINT [PK_Assignments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [OrderId] in table 'IncludedServices'
ALTER TABLE [dbo].[IncludedServices]
ADD CONSTRAINT [FK_OrderIncludedServices]
    FOREIGN KEY ([OrderId])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderIncludedServices'
CREATE INDEX [IX_FK_OrderIncludedServices]
ON [dbo].[IncludedServices]
    ([OrderId]);
GO

-- Creating foreign key on [OrderId] in table 'RoomPackages'
ALTER TABLE [dbo].[RoomPackages]
ADD CONSTRAINT [FK_OrderRoomPackage]
    FOREIGN KEY ([OrderId])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderRoomPackage'
CREATE INDEX [IX_FK_OrderRoomPackage]
ON [dbo].[RoomPackages]
    ([OrderId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------